package com.javaweb.demo.servlet;

import com.javaweb.demo.dao.UserDao;
import com.javaweb.demo.dao.UserDaolmpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DeletePosterServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String id = request.getParameter("id");
        int userId = Integer.parseInt(id);
        String username = request.getParameter("username");
        System.out.println("delete " +username);
        UserDao ud = new UserDaolmpl();
        request.setAttribute("username", username);
        if(ud.deleteposter(userId)) {
            System.out.println("删除成功");
            request.setAttribute("xiaoxi", "删除成功");
            request.setAttribute("username", username);
            request.getRequestDispatcher("/GetPoster").forward(request, response);
        } else {
            request.getRequestDispatcher("/fail.jsp").forward(request, response);
        }
    }

}
